package org.browntooth.app.bluetooth.messaging;

final class BluetoothMessagingUtils {
	private BluetoothMessagingUtils() {
		// Disallow construction
	}
	
	static byte[] buildLengthField(int length) {
		byte[] data = new byte[4];
		
		for(int i = 0; i < 4; i++) {
			data[3 - i] = (byte) (length & 0xff);
			length >>>= 8;
		}
		
		return data;
	}
	
	static int parseLength(byte[] data) {
		int length = 0;
		
		for(int i = 0; i < 4; i++) {
			length <<= 8;
			length |= data[i];
		}
		
		return length;
	}
}
